import random
from debug import *

resource = {}
resource["host"] = 0
resource["nfc1"] = 0
resource["nfc2"] = 0
resource["nfc3"] = 0
resource["nfc4"] = 0
resource["matcher1"] = 0
resource["matcher2"] = 0
resource["CNN"] = 0
resource["KNN"] = 0
resource["arm"] = 0

nfc_count = len(list(filter(lambda x:True if "nfc" in x else False,list(resource))))
matcher_count = len(list(filter(lambda x:True if "matcher" in x else False,list(resource))))

read_count = 0
def read_generator():
    global read_count
    read_count += 1

    task = []
    task.append("读"+str(read_count))

    ch = random.randint(1,nfc_count) #选择这次读哪个channel的数据
    task.append([1,"nfc"+str(ch),200,(0,)])
    task.append([2,"host",20,(1,)])
    task.append([3,"host",5,(2,)])
    
    return task

write_count = 0
def write_generator():
    global write_count
    write_count += 1

    task = []
    task.append("写"+str(write_count))

    ch = random.randint(1,nfc_count) #选择这次读哪个channel的数据
    task.append([1,"nfc"+str(ch),200,(0,)])
    task.append([2,"host",20,(1,)])
    task.append([3,"nfc"+str(ch),600,(2,)])
    task.append([4,"host",5,(3,)])
    
    return task

text_search_count = 0
def text_search_generator():
    global text_search_count
    text_search_count += 1

    task = []
    task.append("文本"+str(text_search_count))

    task.append([1,"host",20,(0,)])  #接受参数
    task.append([2,"nfc1",200,(1,)]) #获取元数据，假设元数据都在同一个块中
    task.append([3,"nfc1",200,(2,)]) #读数据块
    task.append([4,"nfc2",200,(2,)])
    task.append([5,"matcher",150,(3,)]) #进行匹配
    task.append([6,"matcher",150,(4,)])
    task.append([7,"host",20,(5,6)])
    task.append([8,"host",5,(7,)])
    
    return task

image_search_count = 0
def image_search_generator():
    global image_search_count
    image_search_count += 1

    task = []
    task.append("图像"+str(image_search_count))

    task.append([1,"host",20,(0,)])  #接受参数
    #task.append([2,"nfc2",200,(1,)]) #获取模型权重
    task.append([2,"CNN",300,(1,)]) #进行匹配
    task.append([3,"KNN",300,(2,)])
    task.append([4,"host",20,(3,)])
    task.append([5,"host",5,(4,)])
    
    return task

recssd_count = 0
def recssd_generator():
    global recssd_count
    recssd_count += 1

    task = []
    task.append("RecSSD"+str(recssd_count))

    task.append([1,"nfc"+str(random.randint(1,nfc_count)),200,(0,)])
    task.append([2,"arm",25,(1,)])
    task.append([3,"nfc"+str(random.randint(1,nfc_count)),200,(0,)])
    task.append([4,"arm",25,(2,)])
    task.append([5,"nfc"+str(random.randint(1,nfc_count)),200,(0,)])
    task.append([6,"arm",25,(3,)])
    task.append([7,"nfc"+str(random.randint(1,nfc_count)),200,(0,)])
    task.append([8,"arm",25,(4,)])
    task.append([9,"host",20,(2,4,6,8)])
    task.append([10,"host",5,(9,)])

    return task

generator_list = []
generator_list.append(read_generator)
generator_list.append(write_generator)
generator_list.append(text_search_generator)
generator_list.append(image_search_generator)
generator_list.append(recssd_generator)

task_list = []
for i in range(5): #总共生成100个任务
    task_list.append(generator_list[random.randint(0,len(generator_list)-1)]())

#打印每种任务分别多少个
print("读:",read_count)
print("写:",write_count)
print("文本:",text_search_count)
print("图像:",image_search_count)
print("RecSSD:",recssd_count)